package com.szl.group;

import com.szl.group.common.model.Student;
import io.github.burukeyou.dataframe.iframe.SDFrame;
import io.github.burukeyou.dataframe.iframe.item.FI2;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * description: 启动成功之后可以执行的一些逻辑
 * author: shenxiaolong
 * date: 2020/07/01 14:25
 */
@Component
public class WelcomeCommandLineRunner implements CommandLineRunner {


    static List<Student> studentList = new ArrayList<>();

    static {
        studentList.add(new Student(1, "a", "一中", "一年级", 11, new BigDecimal(1)));
        studentList.add(new Student(2, "a", "一中", "一年级", 11, new BigDecimal(1)));
        studentList.add(new Student(3, "b", "一中", "三年级", 12, new BigDecimal(2)));
        studentList.add(new Student(4, "c", "二中", "一年级", 13, new BigDecimal(3)));
        studentList.add(new Student(5, "d", "二中", "一年级", 14, new BigDecimal(4)));
        studentList.add(new Student(6, "e", "三中", "二年级", 14, new BigDecimal(5)));
        studentList.add(new Student(7, "e", "三中", "二年级", 15, new BigDecimal(5)));
    }

    @Override
    public void run(String... args) throws Exception {
        //do something
        System.out.println("*************** The application of SZL-APP started successfully ***************");


// 等价于SQL:
// select school,sum(score)
// from students
// where age is not null and age >=9 and age <= 16
// group by school
// order by sum(score) desc
// limit 2
        SDFrame<FI2<String, BigDecimal>> sdf2 = SDFrame.read(studentList)
                .whereNotNull(Student::getAge)
                .whereBetween(Student::getAge, 9, 16)
                .groupBySum(Student::getSchool, Student::getScore)
                .sortDesc(FI2::getC2)
                .cutFirst(2);

        sdf2.show();
    }

}
